Get the last day of a specified year and monthΒΆ

calendar.monthrange(year, month)[1]

Get the last day of a specified year and month.
import calendar

year = 2015
month = 2
print(calendar.monthrange(year, month)[1])

Output:

28